//
//  ActivityCell.m
//  mendianjieke
//
//  Created by 响当当 on 8/2/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "ActivityCell.h"

@interface ActivityCell()<UIScrollViewDelegate>
@property (nonatomic, strong)UIButton *checkButton;//查看
@property (nonatomic, strong)UILabel *titleLabel;//活动标题
@property (nonatomic, strong)UIImageView *hotImageView;//hot图标
@property (nonatomic, strong)UILabel *hotLabel;//热度
@property (nonatomic, strong)UILabel *activityLabel;//活动
@property (nonatomic, strong)UILabel *timeLabel;//活动时间
@property (nonatomic, strong)UILabel *flowLabel;//流量
@property (nonatomic, strong)UIScrollView *bannerView;
@property (nonatomic, strong)UIPageControl *pageControl;
@property (nonatomic, strong)NSArray *infoArr;

@property (nonatomic, strong)UILabel *noActivityLabel;//

@end

@implementation ActivityCell

- (NSArray *)infoArr
{
    if (!_infoArr)
    {
        _infoArr = [[NSArray alloc]init];
    }
    return _infoArr;
}

- (UIButton *)checkButton
{
    if (!_checkButton)
    {
        UIImageView *lineView = [[UIImageView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,11*kUIScaleBasePlus,18*kUIScaleBasePlus,18*kUIScaleBasePlus)];
        lineView.image = [UIImage imageNamed:@"activity_area"];
        [self.contentView addSubview:lineView];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(lineView.frame)+5*kUIScaleBasePlus,10*kUIScaleBasePlus,80*kUIScaleBasePlus,21*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentLeft
                                                   textClor:LCHexColor(0x282828)
                                                   textFont:15*kUIScaleBasePlus];
        titleLabel.text = @"活动专区";
        [self.contentView addSubview:titleLabel];
        
        
        _checkButton = [Utilties creatButtonWithFrame:CGRectMake(SCREEN_WIDTH-16*kUIScaleBasePlus-80*kUIScaleBasePlus,12*kUIScaleBasePlus,100*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                         textAligment:UIControlContentHorizontalAlignmentLeft
                                                 text:@"立即查看"
                                             textClor:LCHexColor(0xFF7A17)
                                            buttonBGC:[UIColor clearColor]
                                             textFont:13*kUIScaleBasePlus
                                               target:self
                                               method:@selector(check)];
        [_checkButton setImage:[UIImage imageNamed:@"checkArrow"] forState:UIControlStateNormal];
        _checkButton.hidden = YES;
        [_checkButton setLeftTitleAndRightImageWithSpace:1];
        
        UIView *View = [[UIView alloc]initWithFrame:CGRectMake(0,41*kUIScaleBasePlus,SCREEN_WIDTH,1*kUIScaleBasePlus)];
        View.backgroundColor = JSALineColor;
        [self.contentView addSubview:View];
    }
    return _checkButton;
}

- (UIScrollView *)bannerView
{
    if (!_bannerView)
    {
        _bannerView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,42*kUIScaleBasePlus,SCREEN_WIDTH-20*kUIScaleBasePlus,87*kUIScaleBasePlus)];
        _bannerView.bounces = NO;
        _bannerView.pagingEnabled = YES;
        _bannerView.delegate = self;
        _bannerView.showsHorizontalScrollIndicator = NO;
//        [_bannerView setContentOffset:CGPointMake(SCREEN_WIDTH, 0)];
    }
    return _bannerView;
}

- (UIPageControl *)pageControl
{
    if (!_pageControl) {
       _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.bannerView.frame),300*kUIScaleBasePlus,20*kUIScaleBasePlus)];
               _pageControl.currentPageIndicatorTintColor = JSAMainColor;
               _pageControl.pageIndicatorTintColor = LCHexColor(0xE0E0E0);
    }
    return _pageControl;
}

- (UILabel *)noActivityLabel
{
    if (!_noActivityLabel)
    {
        _noActivityLabel = [Utilties creatLabelWithFrame:CGRectMake(0,35*kUIScaleBasePlus,SCREEN_WIDTH-20*kUIScaleBasePlus,20*kUIScaleBasePlus)
        textAligment:NSTextAlignmentCenter
            textClor:LCHexColor(0xE0E0E0)
            textFont:14*kUIScaleBasePlus];
        _noActivityLabel.text = @"暂无活动";
    }
    return _noActivityLabel;
}


- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.checkButton.frame)+27*kUIScaleBasePlus,100*kUIScaleBasePlus,15.5*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                           textClor:LCHexColor(0x000000)
                                           textFont:16*kUIScaleBasePlus];
        _titleLabel.text = @"520，我的爱";
    }
    return _titleLabel;
}

- (UIImageView *)hotImageView
{
    if (!_hotImageView)
    {
        _hotImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.checkButton.frame)+30*kUIScaleBasePlus, 10*kUIScaleBasePlus,11*kUIScaleBasePlus)];
        _hotImageView.image = [UIImage imageNamed:@"activity_hot"];
    }
    return _hotImageView;
}

- (UILabel *)hotLabel
{
    if (!_hotLabel)
    {
        _hotLabel = [Utilties creatLabelWithFrame:CGRectMake(0,CGRectGetMaxY(self.checkButton.frame)+30*kUIScaleBasePlus,50*kUIScaleBasePlus,9*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                              textClor:LCHexColor(0xFFFFFF)
                                              textFont:12*kUIScaleBasePlus];
       
    }
    return _hotLabel;
}


- (UILabel *)activityLabel
{
    if (!_activityLabel)
    {
        _activityLabel = [Utilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH-15*kUIScaleBasePlus-50*kUIScaleBasePlus,CGRectGetMaxY(self.checkButton.frame)+27*kUIScaleBasePlus,50*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                              textClor:LCHexColor(0xFFFFFF)
                                              textFont:12*kUIScaleBasePlus];
        _activityLabel.backgroundColor = LCHexColor(0xFF7A17);
        _activityLabel.layer.masksToBounds = YES;
        _activityLabel.layer.cornerRadius = _activityLabel.frame.size.height/2;
        _activityLabel.text = @"进行中";
    }
    return _activityLabel;
}

- (UILabel *)flowLabel
{
    if (!_flowLabel)
    {
        _flowLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.titleLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,13.5*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                          textFont:14*kUIScaleBasePlus];
        _flowLabel.text = @"活动成交：289298元";
    }
    return _flowLabel;
}

- (UILabel *)timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.flowLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,9*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                          textFont:12*kUIScaleBasePlus];
        _timeLabel.text = @"活动时间：2019-02-28～2019";
    }
    return _timeLabel;
}



- (void)setFrame:(CGRect)frame
{
    frame.origin.x += 10*kUIScaleBasePlus;
    
    frame.size.width -= 2 * 10*kUIScaleBasePlus;
    
    [super setFrame:frame];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.layer.cornerRadius = 10;
        self.layer.masksToBounds = YES;
        
        [self.contentView addSubview:self.checkButton];
        [self.contentView addSubview:self.bannerView];
        [self.contentView addSubview:self.pageControl];

    }
    
    return self;
}

#pragma mark - Method
- (void)check
{
    
}

- (void)getActivityInfo:(NSArray *)arr
{
 
    if (self.noActivityLabel)
    {
        [self.noActivityLabel removeFromSuperview];
    }
    
    self.infoArr = arr;
    
    self.bannerView.contentSize = CGSizeMake((SCREEN_WIDTH-20*kUIScaleBasePlus)* (arr.count), 87*kUIScaleBasePlus);
    
    CGFloat width = SCREEN_WIDTH-20*kUIScaleBasePlus;

    for (UIView *view in self.bannerView.subviews)
    {
        [view removeFromSuperview];
    }
    
    for (int i=0; i<arr.count; i++)
    {
        ActivityModel *model = [[ActivityModel alloc]initWithDic:arr[i]];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,15*kUIScaleBasePlus,100*kUIScaleBasePlus,15.5*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                           textClor:LCHexColor(0x000000)
                                           textFont:16*kUIScaleBasePlus];
        titleLabel.text = model.name;
        [self.bannerView addSubview:titleLabel];
        [titleLabel sizeToFit];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame)+10*kUIScaleBasePlus,18*kUIScaleBasePlus,10*kUIScaleBasePlus,11*kUIScaleBasePlus)];
        imageView.image = [UIImage imageNamed:@"activity_hot"];
        [self.bannerView addSubview:imageView];
        
        UILabel *hotLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame)+4*kUIScaleBasePlus,17*kUIScaleBasePlus,28*kUIScaleBasePlus,9*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft
                                                 textClor:LCHexColor(0xE74A3A)
                                                 textFont:12*kUIScaleBasePlus];
        hotLabel.text = model.peopleCount.stringValue;
        [hotLabel sizeToFit];
        [self.bannerView addSubview:hotLabel];
        
        UILabel *activityLabel = [Utilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH-50*kUIScaleBasePlus-30*kUIScaleBasePlus,15*kUIScaleBasePlus,50*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                              textClor:LCHexColor(0xFFFFFF)
                                              textFont:12*kUIScaleBasePlus];
        activityLabel.backgroundColor = LCHexColor(0xFF7A17);
        activityLabel.layer.masksToBounds = YES;
        activityLabel.layer.cornerRadius = activityLabel.frame.size.height/2;
        activityLabel.text = @"进行中";
        [self.bannerView addSubview:activityLabel];

        
        UILabel *flowLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,CGRectGetMaxY(activityLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,13.5*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft
                                                 textClor:LCHexColor(0x212121)
                                                 textFont:14*kUIScaleBasePlus];
               flowLabel.text = [NSString stringWithFormat:@"活动成交：%@元",model.totalAmount.stringValue];
               [self.bannerView addSubview:flowLabel];
        
        UILabel *timeLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,CGRectGetMaxY(flowLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,9*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x8A8A8A)
                                                  textFont:12*kUIScaleBasePlus];
        timeLabel.text = [NSString stringWithFormat:@"%@~%@",[Utilties getTime:model.startTime.stringValue],[Utilties getTime:model.endTime.stringValue]];
        [self.bannerView addSubview:timeLabel];
    }
    
    self.pageControl.numberOfPages = self.infoArr.count;
    self.pageControl.currentPage = 0;
}

- (void)getNoActivityInfo
{
    self.bannerView.contentSize = CGSizeMake((SCREEN_WIDTH-20*kUIScaleBasePlus), 87*kUIScaleBasePlus);

    [self.bannerView addSubview:self.noActivityLabel];
}


//完成拖拽
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //偏移到了第几个图片
    NSInteger pageBtn = (scrollView.contentOffset.x *kUIScaleBasePlus)/(SCREEN_WIDTH - 20*kUIScaleBasePlus);
    self.pageControl.currentPage = pageBtn;
    
}

@end
